package red.mlz.module.module.category.mapper;


import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import red.mlz.module.module.category.entity.Category;

import java.math.BigInteger;
import java.util.List;

/**
 * <p>
 * 分类表 Mapper 接口
 * </p>
 *
 * @author mlzred
 * @since 2025-04-03
 */
public interface CategoryMapper {
    @Select("select * from category WHERE id=#{id} and is_deleted = 0")
    Category getById(@Param("id") BigInteger id);

    @Select("select * from category WHERE id=#{id}")
    Category extractById(@Param("id") BigInteger id);

    int update(@Param("Category") Category category);

    int insert(@Param("Category") Category category);

    @Update("update category set is_deleted=1, update_time=#{time} where id=#{id} limit 1")
    void delete(@Param("id") BigInteger id, @Param("time") Integer time);

    @Select("SELECT id FROM category WHERE `name` LIKE concat('%',#{name},'%') limit 999")
    List<BigInteger> getIdsByName(@Param("name") String name);


//    @Select("select * from category WHERE is_deleted = 0 limit 999")
    List<Category> listByIdsAndParentIds(@Param("ids") String categoryIds, @Param("parentId") String parentId);

    List<Category> getCategoryList(@Param("begin") int begin, @Param("size") int size,
                                   @Param("key") String key);


}
